#include "elf_header_widget.h"

ELFHeaderWIdget::ELFHeaderWIdget(QWidget *parent)
    : QWidget{parent}
    , labMagicNumber(new QLabel("MagicNumber"))
    , labObjectFileTyoe(new QLabel("ObjectFileTyoe"))
    , labArchitecture(new QLabel("Architecture"))
    , labObjectFileVersion(new QLabel("ObjectFileVersion"))
    , labEntryPointVirtualAddress(new QLabel("EntryPointVirtualAddress"))
    , labProgramHeaderOffset(new QLabel("ProgramHeaderOffset"))
    , labSectionHeaderOffset(new QLabel("SectionHeaderOffset"))
    , labProcessorSpecificFlags(new QLabel("ProcessorSpecificFlags"))
    , labElfHeaderSize(new QLabel("ElfHeaderSize:"))
    , labProgramHeaderSize(new QLabel("ProgramHeaderSize:"))
    , labProgramHeaderNumber(new QLabel("ProgramHeaderNumber:"))
    , labSectionHeaderSize(new QLabel("SectionHeaderSize:"))
    , labSectionHeaderNumber(new QLabel("SectionHeaderNumber:"))
    , labSectionHeaderStringTableIndex(new QLabel("SectionHeaderStringTableIndex:"))
    , editMagicNumber(new QLineEdit())
    , editObjectFileTyoe(new QLineEdit())
    , editArchitecture(new QLineEdit())
    , editObjectFileVersion(new QLineEdit())
    , editEntryPointVirtualAddress(new QLineEdit())
    , editProgramHeaderOffset(new QLineEdit())
    , editSectionHeaderOffset(new QLineEdit())
    , editProcessorSpecificFlags(new QLineEdit())
    , editElfHeaderSize(new QLineEdit())
    , editProgramHeaderSize(new QLineEdit())
    , editProgramHeaderNumber(new QLineEdit())
    , editSectionHeaderSize(new QLineEdit())
    , editSectionHeaderNumber(new QLineEdit())
    , editSectionHeaderStringTableIndex(new QLineEdit())
    , mainLayout(new QGridLayout())
{
    intiUI();
}

void ELFHeaderWIdget::updateData(ELF_HEADER elf_header)
{
    editMagicNumber->setText(QString(elf_header.strMagicNumber.c_str()));
    editObjectFileTyoe->setText(QString(elf_header.strObjectFileTyoe.c_str()));
    editArchitecture->setText(QString(elf_header.strArchitecture.c_str()));
    editObjectFileVersion->setText(QString(elf_header.strObjectFileVersion.c_str()));
    editEntryPointVirtualAddress->setText(QString(elf_header.strEntryPointVirtualAddress.c_str()));
    editProgramHeaderOffset->setText(QString(elf_header.strProgramHeaderOffset.c_str()));
    editSectionHeaderOffset->setText(QString(elf_header.strSectionHeaderOffset.c_str()));
    editProcessorSpecificFlags->setText(QString(elf_header.strProcessorSpecificFlags.c_str()));
    editElfHeaderSize->setText(QString(elf_header.strElfHeaderSize.c_str()));
    editProgramHeaderSize->setText(QString(elf_header.strProgramHeaderSize.c_str()));
    editProgramHeaderNumber->setText(QString(elf_header.strProgramHeaderNumber.c_str()));
    editSectionHeaderSize->setText(QString(elf_header.strSectionHeaderSize.c_str()));
    editSectionHeaderNumber->setText(QString(elf_header.strSectionHeaderNumber.c_str()));
    editSectionHeaderStringTableIndex->setText(QString(elf_header.strSectionHeaderStringTableIndex.c_str()));
}

void ELFHeaderWIdget::intiUI()
{
    mainLayout->addWidget(labMagicNumber,0,0);
    mainLayout->addWidget(labObjectFileTyoe,1,0);
    mainLayout->addWidget(labArchitecture,2,0);
    mainLayout->addWidget(labObjectFileVersion,3,0);
    mainLayout->addWidget(labEntryPointVirtualAddress,4,0);
    mainLayout->addWidget(labProgramHeaderOffset,5,0);
    mainLayout->addWidget(labSectionHeaderOffset,6,0);
    mainLayout->addWidget(labProcessorSpecificFlags,7,0);
    mainLayout->addWidget(labElfHeaderSize,8,0);
    mainLayout->addWidget(labProgramHeaderSize,9,0);
    mainLayout->addWidget(labProgramHeaderNumber,10,0);
    mainLayout->addWidget(labSectionHeaderSize,11,0);
    mainLayout->addWidget(labSectionHeaderNumber,12,0);
    mainLayout->addWidget(labSectionHeaderStringTableIndex,13,0);

    mainLayout->addWidget(editMagicNumber,0,1);
    mainLayout->addWidget(editObjectFileTyoe,1,1);
    mainLayout->addWidget(editArchitecture,2,1);
    mainLayout->addWidget(editObjectFileVersion,3,1);
    mainLayout->addWidget(editEntryPointVirtualAddress,4,1);
    mainLayout->addWidget(editProgramHeaderOffset,5,1);
    mainLayout->addWidget(editSectionHeaderOffset,6,1);
    mainLayout->addWidget(editProcessorSpecificFlags,7,1);
    mainLayout->addWidget(editElfHeaderSize,8,1);
    mainLayout->addWidget(editProgramHeaderSize,9,1);
    mainLayout->addWidget(editProgramHeaderNumber,10,1);
    mainLayout->addWidget(editSectionHeaderSize,11,1);
    mainLayout->addWidget(editSectionHeaderNumber,12,1);
    mainLayout->addWidget(editSectionHeaderStringTableIndex,13,1);
    setMinimumWidth(500);
    setLayout(mainLayout);
}
